package com.hcms.common.config;

import com.hcms.common.exception.GlobalExceptionHandler;
import com.hcms.common.service.ICaptchaService;
import com.hcms.common.service.IEmailService;
import com.hcms.common.service.IOssService;
import com.hcms.common.service.IRedisService;
import com.hcms.common.service.impl.CaptchaServiceImpl;
import com.hcms.common.service.impl.EmailServiceImpl;
import com.hcms.common.service.impl.LocalStorageServiceImpl;
import com.hcms.common.service.impl.RedisServiceImpl;
import com.hcms.common.util.JwtTokenUtil;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration
@Import({RedisServiceConfig.class})
public class CommonAutoConfiguration {

    /**
     * JWT配置
     */
    @Bean
    public CmsJwtProperties jwtConfig() {
        return new CmsJwtProperties();
    }

    @Bean
    public JwtTokenUtil jwtTokenUtil() {
        return new JwtTokenUtil();
    }

    /**
     * EMAIL配置
     */
    @Bean
    public SpringMailProperties springMailProperties() {
        return new SpringMailProperties();
    }

    @Bean
    public IEmailService emailService() {
        return new EmailServiceImpl();
    }

    /**
     * REDIS配置
     */
    @Bean
    public IRedisService redisService() {
        return new RedisServiceImpl();
    }

    /**
     * OSS对象存储配置
     */
    @Bean
    @ConditionalOnMissingBean(IOssService.class)
    public IOssService ossService() {
        return new LocalStorageServiceImpl();
    }

    /**
     * 验证码配置
     */
    @Bean
    public ICaptchaService captchaService() {
        return new CaptchaServiceImpl();
    }

    /**
     * 全局错误处理
     */
    @Bean
    public GlobalExceptionHandler globalExceptionHandler() {
        return new GlobalExceptionHandler();
    }

}
